package com.shensi.adminCollect.controller.coupon;

import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.common.utils.poi.ExcelUtil;
import com.shensi.adminCollect.domain.coupon.CouponIssueRelation;
import com.shensi.adminCollect.service.coupon.ICouponIssueRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 发放方式，优惠劵信息Controller
 *
 * @author qujia
 * @date 2021-08-13
 */
@RestController
@RequestMapping("/coupon/detail")
public class CouponIssueRelationController extends BaseController
{
    @Autowired
    private ICouponIssueRelationService couponIssueRelationService;

    /**
     * 查询发放方式，优惠劵信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CouponIssueRelation couponIssueRelation)
    {
        startPage();
        List<CouponIssueRelation> list = couponIssueRelationService.selectCouponIssueRelationList(couponIssueRelation);
        return getDataTable(list);
    }

    /**
     * 导出发放方式，优惠劵信息列表
     */
    @GetMapping("/export")
    public AjaxResult export(CouponIssueRelation couponIssueRelation)
    {
        List<CouponIssueRelation> list = couponIssueRelationService.selectCouponIssueRelationList(couponIssueRelation);
        ExcelUtil<CouponIssueRelation> util = new ExcelUtil<CouponIssueRelation>(CouponIssueRelation.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取发放方式，优惠劵信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(couponIssueRelationService.selectCouponIssueRelationById(id));
    }

    /**
     * 新增发放方式，优惠劵信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody CouponIssueRelation couponIssueRelation)
    {
        return toAjax(couponIssueRelationService.insertCouponIssueRelation(couponIssueRelation));
    }

    /**
     * 修改发放方式，优惠劵信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CouponIssueRelation couponIssueRelation)
    {
        return toAjax(couponIssueRelationService.updateCouponIssueRelation(couponIssueRelation));
    }

    /**
     * 删除发放方式，优惠劵信息
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(couponIssueRelationService.deleteCouponIssueRelationByIds(ids));
    }
}
